package com.mou.aiagent.rag;
import jakarta.annotation.Resource;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.List;
/**
 * (基于内存存储向量数据库和转换)
 */
@Configuration
public class LoveAppVectorStoreConfig {
    @Resource
    private LoveAppDocumentLoader loveAppDocumentLoader;
    @Resource
    private MyKeywordEnricher myKeywordEnricher;
    @Bean
    // 创建一个名为loveAppVectorStore的VectorStore类型的Bean
    VectorStore loveAppVectorStore(EmbeddingModel embeddingModel) {
         // impleVectorStore基于内存存储
        // 创建一个SimpleVectorStore类型的对象，并传入embeddingModel参数
        SimpleVectorStore simpleVectorStore = SimpleVectorStore.builder(embeddingModel).build();
        // 加载loveAppDocumentLoader中的文档
        List<Document> documents = loveAppDocumentLoader.loadDocuments();
        // 自动补充关键元信息
        List<Document> documents1 = myKeywordEnricher.enrichDocuments(documents);
        // 将加载的文档添加到simpleVectorStore中
        simpleVectorStore.add(documents1);
       return simpleVectorStore;
    }
}
